﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels;
using HR_Implements;
namespace HostApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        TcpChannel channel = null;
        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            try{
                EmployeeRemotingObject h = new EmployeeRemotingObject ();
                //create chanel
            channel = new TcpChannel(int.Parse(textBox1.Text));
            // dang ki chanel

            RemotingConfiguration.RegisterWellKnownServiceType(typeof(EmployeeRemotingObject), "EmployeeRemotingObject", WellKnownObjectMode.SingleCall);
            //

            ChannelServices.RegisterChannel(channel);
                 toolStripStatusLabel1.Text= "Start";
            }catch(Exception ex ){
                toolStripStatusLabel1.Text= "Error";
                MessageBox.Show(ex.Message);
            }
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                ChannelServices.UnregisterChannel(channel);
                toolStripStatusLabel1.Text="Stop";
            }catch(Exception ex){
                toolStripStatusLabel1.Text = "Error";
                MessageBox.Show(ex.Message);
            }

        }
    }
}
